<!-- #layout name=empty -->
<div class="container">
    <div class="row">
        <div class="col-sm-6 col-sm-offset-3 col-md-4 col-md-offset-4">
            <div class="block-small-form">
                <div class="logo">
                    <img src="/_Admin/Images/logo-blue.png" alt="Logo">
                </div>
                <form data-bind="submit: onSubmit">
                    <div class="form-group">
                        <label class="sr-only">Email</label>
                        <input class="form-control" type="text" data-bind="value: email, error: email" placeholder="Email address" />
                    </div>
                    <div class="form-group">
                        <p class="form-control-static">After submiting your request, we will send you a verification mail, please check in time</p>
                    </div>

                    <a class="btn gray pull-left" data-bind="attr: { href: loginPageUrl }">Back</a>
                    <button class="btn blue pull-right" type="submit">Submit</button>
                </form>
            </div>
        </div>
    </div>
</div>
<script>
    $(function() {

        var forgotPasswordVM = function() {
            var self = this;

            this.isValid = function() {
                return self.email.isValid();
            }

            this.onSubmit = function() {
                if (self.isValid()) {
                    Kooboo.User.ForgotPassword({
                        email: self.email()
                    }).then(function(res) {

                        if (res.success) {
                            window.info.show(res.model, true);
                        }
                    })
                } else {
                    self.showError(true);
                }
            }

            this.showError = ko.observable(false);

            this.email = ko.validateField({
                required: Kooboo.text.validation.required,
                regex: {
                    pattern: /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,
                    message: Kooboo.text.validation.emailInvalid
                }
            })

            this.loginPageUrl = Kooboo.Route.Get(Kooboo.Route.User.LoginPage);
        }

        var fp = new forgotPasswordVM();
        ko.applyBindings(fp, document.getElementsByClassName("container")[0]);
    });
</script>